Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: valid Pydantic #373

Closed

Conversation

Jhonnyr97
Copy link
Contributor

Description

I verify that I required of pydantic is respected in payloads with validate_presences
Related to issue #(cheshire-cat-ai/admin-vue#27)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

# set a different LLM
invented_url = "https://example.com"
payload = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for writing the test

return get_setting_by_name(payload.name)

def validate_presences(required: list, payload: dict):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the utility of a validate_presences method, but it is not related to DB crud.
I would move it here in the factory, where schemas are defined, or in utilis in case we'll use this validation method also for plugin settings. Also infrastructure could be a place for this method, if we go for a validation set of methods

What do you think?

@@ -54,7 +54,17 @@ def upsert_embedder_setting(
status_code=400,
detail=f"{languageEmbedderName} not supported. Must be one of {allowed_configurations}",
)


required = EMBEDDER_SCHEMAS[languageEmbedderName]['required']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there always a required key?

required = EMBEDDER_SCHEMAS[languageEmbedderName]['required']
if crud.validate_presences(required, payload):
raise HTTPException(
status_code=405,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's go for 400 (bad request)


# check immediate response
assert response.status_code == 405
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's go for 400 (bad request)

# Conflicts:
#	core/cat/routes/setting/embedder_setting.py
#	core/cat/routes/setting/llm_setting.py
#	core/tests/routes/setting/test_llm_setting.py
@Jhonnyr97 Jhonnyr97 closed this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants